package com.xw.wuliu.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * List view base adapter class
 * Adapters that subclasses this base class will be used in various kinds of list views
 * including system default list view control and the custom unrolled list view
 * 
 * @author Neusoft.E3
 * 
 */
public abstract class ListBaseAdapter extends BaseAdapter {
    protected LayoutInflater  mLayoutInflater; // layout inflater
    protected int             mResource;      // item layout resource
    protected ArrayList<?>    mData;          // list data
    protected Context         mContext;       // parent
    protected OnClickListener mClickListener; // item click listener, not used in every case

    /**
     * Constructor
     * 
     * @param aContext parent
     * @param aData list data
     * @param aResource item layout resource
     */
    public ListBaseAdapter( Context aContext, ArrayList<?> aData ) {
        mContext = aContext.getApplicationContext();
        mData = aData;
        mLayoutInflater = ( LayoutInflater ) aContext
                .getSystemService( Context.LAYOUT_INFLATER_SERVICE );
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem( int position ) {
        return mData.get( position );
    }

    public void reflash( ArrayList<?> reflashData ) {
        mData = reflashData;
        notifyDataSetChanged();
    }

    @Override
    public long getItemId( int position ) {
        return position;
    }

    @Override
    public abstract View getView( int position, View convertView, ViewGroup parent );

    /**
     * Set item click listener
     * 
     * @param aListener
     */
    public void setItemOnClickListener( OnClickListener aListener ) {
        mClickListener = aListener;
    }

}
